home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / BREAKUP.C < prev    next >
C/C++ Source or Header  |  1991-08-13  |  4KB  |  170 lines

  1. /* -*-C-*-
  2.  
  3. Copyright (c) 1987-91 Massachusetts Institute of Technology
  4.  
  5. This material was developed by the Scheme project at the Massachusetts
  6. Institute of Technology, Department of Electrical Engineering and
  7. Computer Science.  Permission to copy this software, to redistribute
  8. it, and to use it for any purpose is granted, subject to the following
  9. restrictions and understandings.
  10.  
  11. 1. Any copy made of this software must include this copyright notice
  12. in full.
  13.  
  14. 2. Users of this software agree to make their best efforts (a) to
  15. return to the MIT Scheme project any improvements or extensions that
  16. they make, so that these may be included in future releases; and (b)
  17. to inform MIT of noteworthy uses of this software.
  18.  
  19. 3. All materials developed as a consequence of the use of this
  20. software shall duly acknowledge such use, in accordance with the usual
  21. standards of acknowledging credit in academic research.
  22.  
  23. 4. MIT has made no warrantee or representation that the operation of
  24. this software will be error-free, and MIT is under no obligation to
  25. provide any services, by way of maintenance, update, or otherwise.
  26.  
  27. 5. In conjunction with products arising from the use of this material,
  28. there shall be no use of the name of the Massachusetts Institute of
  29. Technology nor of any adaptation thereof in any advertising,
  30. promotional, or sales literature without prior written consent from
  31. MIT in each case. */
  32.  
  33. /* $Header: /scheme/microcode/RCS/Breakup.c,v 9.23 1991/08/13 06:20:37 cph Exp $ */
  34.  
  35. #include <stdio.h>
  36.  
  37. #ifndef isdigit
  38. #include <ctype.h>
  39. #endif
  40.  
  41. #define boolean char
  42. #define false 0
  43. #define true 1
  44.  
  45. #define isoctal(c) (isdigit(c) && (c != '8') && (c != '9'))
  46.  
  47. int get_a_char()
  48. { register int c;
  49.   register int count = 2;
  50.   for (c = getchar();
  51.        isoctal(c) && count >= 0;
  52.        c = getchar(), count -=1)
  53.     putchar(c);
  54.   if (count != 2) return c;
  55.   putchar(c);
  56.   return getchar();
  57. }
  58.  
  59. main()
  60. { register int c;
  61.   register boolean after_new_line = true;
  62.   while ((c = getchar()) != EOF)
  63. re_dispatch:
  64.     switch(c)
  65.     { case '\f':
  66.     break;
  67.       case ',':
  68.     putchar(c);
  69.     while (((c = getchar()) == ' ') || (c == '\t'))
  70.         if (c == EOF)
  71.         { fprintf(stderr, "Confused expression: ,\n");
  72.       exit(1);
  73.         }
  74.     if (c == '\n')
  75.     { putchar(c);
  76.       after_new_line = true;
  77.       break;
  78.     }
  79.     putchar(' ');
  80.     goto re_dispatch;
  81.       case ';':
  82.       case ':':
  83.       case '?':
  84.       case '}':
  85.     putchar(c);
  86.         putchar('\n');
  87.     after_new_line = true;
  88.         break;
  89.       case '\n':
  90.     if (!after_new_line)
  91.     { after_new_line = true;
  92.       putchar('\n');
  93.         }
  94.     break;
  95.       case '\'':
  96.     putchar(c);
  97.     c = getchar();
  98.     if (c == EOF)
  99.     { fprintf(stderr, "Confused character: EOF\n");
  100.       exit(1);
  101.     }
  102.     putchar(c);
  103.     if (c == '\n')
  104.     { fprintf(stderr, "Confused character: \\n\n");
  105.       after_new_line = true;
  106.       break;
  107.     }
  108.     if (c == '\'')
  109.     { fprintf(stderr, "Confused character: \\\'\n");
  110.       break;
  111.     }
  112.     if (c == '\\')
  113.       c = get_a_char();
  114.     else c = getchar();
  115.     if (c == EOF)
  116.     { fprintf(stderr, "Confused character: EOF\n");
  117.       exit(1);
  118.     }
  119.     putchar(c);
  120.     if (c != '\'')
  121.       fprintf(stderr, "Confused character: %c = 0x%x\n",
  122.           c);
  123.     break;
  124.       case '"':
  125.     after_new_line = false;
  126.     putchar(c);
  127.     c = getchar();
  128.     while (true)
  129.     { while ((c != EOF) &&
  130.          (c != '"') &&
  131.          (c != '\n') &&
  132.          (c != '\\'))
  133.       { putchar(c);
  134.         c = getchar();
  135.       }
  136.       if (c == EOF)
  137.       { fprintf(stderr, "Confused string: EOF\n");
  138.         exit(1);
  139.       }
  140.       putchar(c);
  141.       if (c == '\n')
  142.       { fprintf(stderr, "Confused string: \\n\n");
  143.         after_new_line = true;
  144.         break;
  145.       }
  146.           if (c == '"') break;
  147.       if (c == '\\')
  148.         c = get_a_char();
  149.     }
  150.     break;
  151.       case '#':
  152.     if (after_new_line)
  153.     { while (((c = getchar()) != EOF) && (c != '\n')) ;
  154.              if (c == EOF) exit(0);
  155.       break;
  156.     }
  157.     putchar(c);
  158.     break;
  159.       case '{':
  160.     if (!after_new_line)
  161.           putchar('\n');
  162.         /* Fall Through */
  163.       default:
  164.     after_new_line = false;
  165.     putchar(c);
  166.     }
  167.   fflush(stdout);
  168.   exit(0);
  169. }
  170.